﻿/****************************************************************************************/
/***
####################################################################################进度条
***/
function SetProgressBar(ShowText)
{
    var iWidth = document.documentElement.clientWidth; 
    var iHeight = document.documentElement.clientHeight; 
    
    var BackGround = document.getElementById("ProgressBar_BackGround");
    if(!BackGround)
    {    
        var BackGround = document.createElement("div"); 
        BackGround.id = "ProgressBar_BackGround";
        BackGround.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.2;background-color:#000000;z-index:101;";
        document.body.appendChild(BackGround); 
    }
    else
    {
        BackGround.style.display="block";
    }

    var ProgressBarSide = document.getElementById("ProgressBar_ProgressBarSide");
    if(!ProgressBarSide)
    {
        var ProgressBarSide=document.createElement("div");
        ProgressBarSide.id = "ProgressBar_ProgressBarSide";
        ProgressBarSide.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-200)/2+"px;left:"+(iWidth-400)/2+"px;width:"+400+"px;height:"+200+"px;text-align:center;border:1px solid ;background-color:#fff;padding:1px;line-height:22px;z-index:102;";
        document.body.appendChild(ProgressBarSide);
        
        var divP = document.createElement("div");
        divP.id="status";
        divP.style.cssText = "font: 12px '宋体';padding-top: 60px ; ";//font-weight: bold;";
        divP.innerHTML = ShowText;

        var img = document.createElement("img");
        img.style.cssText = "padding-top: 10px ; "
        img.src="img_ct/ajax_run.gif";

        ProgressBarSide.appendChild(divP);
        ProgressBarSide.appendChild(img);    
    }
    else
    {
        ProgressBarSide.style.display="block";
    }
}

function GoMerchant()
{
    window.open("http://www.ctrip.com/merchant/");
    
    var BackGround = document.getElementById("ProgressBar_BackGround");
    var ProgressBarSide = document.getElementById("ProgressBar_ProgressBarSide");
    
    if(BackGround){BackGround.style.display="none";}
    if(ProgressBarSide){ProgressBarSide.style.display="none";}
}

function LinkToMerchant()
{
    SetProgressBar('<b><p>星悦汇会员<b>持卡</b>可享受携程3000余家特约商户的消费者折扣</p><br/><p>您现在正跳转至携程VIP特约商户页面，<b>查询打折商户信息</b></p><b>');
    setTimeout('GoMerchant()',3000);
}

/****************************************************************************************/
/***
####################################################################################数组转ＸＭＬ
***/

//<%-- 用于生成一个简单的xml arrTotal:数组，obj:根节点名称    --%>
function overLoadconvertArrayToXML(arrTotal,obj)
{
    var sRet = "";
    
    for (var i=0;i<arrTotal.length;i++)
    {
        sRet+="<"+obj+">";
        var node = convertArrayToXmlNode(arrTotal[i]);
        sRet += node;
        sRet+="</"+obj+">";
    }
    return sRet;
}

//参数为：多个范型组成的数组
function convertMultiArrayToXML(arrList)
{
    var sRet = "";
    sRet="<List>";
    for (var i=0;i<arrList.length;i++)
    {
        sRet +="<ParaList>";
        
        sRet +=convertArrayToXML(arrList[i]);
        
        sRet +="</ParaList>";
    }    
    sRet+="</List>";
    return sRet;
}

//参数为一个范型的数组
function convertArrayToXML(arrTotal)
{
    var sRet = "";
    sRet +="<QueryList>";
    for (var i=0;i<arrTotal.length;i++)
    {
        sRet +="<QueryDetail>";
        
        var node = convertArrayToXmlNode(arrTotal[i]);
        sRet += node;

        sRet +="</QueryDetail>";
    }
    sRet +="</QueryList>";
    
    return sRet;
}

function convertArrayToXmlNode(arrNode)
{
    var sRet = "";
    for (var i=0;i<arrNode.length;i++)
    {
        var element = convertArrayToXmlElement(arrNode[i]);
        sRet += element;
    }
    
    return sRet;
}

function convertArrayToXmlElement(arrElement)
{
    var preFix = "<"+arrElement[0]+">";
    var suffix = "</"+arrElement[0]+">";
    
    var sValue = "";
    if (Object.prototype.toString.apply(arrElement[1]) === '[object Array]')    
    {
        for (var i=1;i<arrElement.length;i++)
        {
            sValue += convertArrayToXmlElement(arrElement[i]);
        }
    }
    else
    {
        sValue = arrElement[1];
    }
    
    return preFix + sValue + suffix;
}



/****************************************************************************************/
/***
####################################################################################验证类
***/

//验证email地址
function isEmail(sValue)
{
    var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    return reg.test(sValue);
}

//验证手机号码
function isMobile(sValue)
{
    var reg=/^((13[0-9]|15[0-9]|18[0-9]|14[7])\d{8}$)/;
    return reg.test(sValue);
}

//验证数字
function check_number(obj)   
{     
    var reg = /^\d+$/;  
    return reg.test(obj);
}

/****************************************************************************************/
/***
####################################################################################工具类
***/

//显示一个Div
function showDiv(objSource,objThis,objX,objY)
{
//    if(typeof(objSource)=="object"&&typeof(objSource)=="object")
//    {
//        var r = getAbsolutePos(objThis[0]);
//        var x = typeof(objX)=="number"?r.x+"px":r.x+"px";
//        var y = typeof(objX)=="number"?r.y+"px":r.y+"px";
//        
//        objSource[0].style.left=r.x;
//        objSource[0].style.top=r.y;
//        objSource[0].style.display = "block";
//    }
    var showDiv=document.getElementById(objSource);
    if (showDiv){
        var r = getAbsolutePos(objThis);
        var x = typeof(objX)=="number"?objX+r.x+objThis.offsetWidth+"px":r.x+"px";
        var y = typeof(objX)=="number"?objX+r.y+objThis.offsetHeight+"px":r.y+objThis.offsetHeight+"px";  
        showDiv.style.left=x;
        showDiv.style.top=y;
        showDiv.style.display = "block";
    }
}

//隐藏一个DIV
function hideDiv(obj)
{
    document.getElementById(obj).style.display="none";
}

//获取坐标
function getAbsolutePos(el)
{
    var SL = 0, ST = 0;
    var is_div = /^div$/i.test(el.tagName);
    if (is_div && el.scrollLeft)
    SL = el.scrollLeft;
    if (is_div && el.scrollTop) 
    ST = el.scrollTop;
    var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
    if (el.offsetParent)
    {
        var tmp = this.getAbsolutePos(el.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
}

//转换xml
function toXML(strxml)
{ 
    try
    { 
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
        xmlDoc.loadXML(strxml); 
    } 
    catch(e)
    { 
        var oParser=new DOMParser(); 
        xmlDoc=oParser.parseFromString(strxml,"text/xml"); 
    } 
    return xmlDoc; 
}

//html转换
function HtmlDecode(text)   
{   
      return   text.replace(/&amp;/g,   '&').replace(/&quot;/g,   '\"').replace(/&lt;/g,   '<').replace(/&gt;/g,   '>');   
} 

//给定一个日期往后加几天
function  addDay(date,dayCount)
{   
    var d=new Date(date.replace(/-/g,"/"));   
    d.setDate(d.getDate()+parseInt(dayCount));   
    var strDate=(1+d.getMonth())+"/"+d.getDate()+"/"+d.getFullYear();   
    var arr=strDate.split('/');
    return arr[2]+"-"+arr[0]+"-"+arr[1];
}
//比较日期　
function compareDate(startDate,endDate)
{
    if(startDate=="" && endDate=="")
        return true;
    var strdt1=startDate.replace(/-/g, "/");
    var strdt2=endDate.replace(/-/g, "/");
    var dt1=new Date(Date.parse(strdt1));
    var dt2=new Date(Date.parse(strdt2));

    if(dt1<dt2)
       return true;
    else 
        return false;
}
//日期格式转换(yyyy-MM-dd)
function conDate(vD)
{
    var arr=vD.split('-');
    var ret=arr[0]+"-";
    if(arr[1].length==1){
        ret+="0"+arr[1]+"-";
    }
    else{
        ret+=arr[1]+"-";
    }
    if(arr[2].length==1){
        ret+="0"+arr[2];
    }
    else{
        ret+=arr[2];
    }
    return ret;
}
//计算两个日期差
function getDateDiff(date1,date2)
{
    var re=/^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;   
    var dt1,dt2;   
    if(re.test(date1))   
    {   
         dt1=new Date(RegExp.$1,RegExp.$2-1,RegExp.$3);   
    } 

    if(re.test(date2))   
    {   
         dt2 =new Date(RegExp.$1,RegExp.$2-1,RegExp.$3);   
    }  
    var days=Math.floor((dt2-dt1)/(1000 * 60 * 60 * 24));
    if(days==0)
    {
        days=1;
    }
    return days;
}

//阻止冒泡
function stopbubble(e){
    if(e && e.stoppropagation()){
        e.stoppropagation();            
    } else {
        window.event.cancelbubble = true;    
    }
}

//比较数组[返回相同的]
function ArrayCompare(arr1,arr2){
    var arrSame= new Array();
    for(var i1 in arr1){
        for(var i2 in arr2){
            if(arr1[i1]==arr2[i2]){
                arrSame.push(arr1[i1]);
            }
        }
    }
    return arrSame
}


/****************************************************************************************/
//检查输入
function CheckInput(objShow,objSource,objMsg){
    objSource=objSource.tagName=="INPUT"?objSource:objSource[0];
    objSource.focus();
    objSource.select();
    var temp = getAbsolutePos(objSource);
   
    var x = temp.x-5+"px";
    var y = temp.y-objSource.offsetHeight-10+"px";
    
    var obj = document.getElementById(objShow);
    obj.innerHTML=objMsg;
    obj.style.left=x;
    obj.style.top=y;
    obj.style.display = "block";
    $(obj).fadeOut(4000); 

    /*
    var sInnnerMsg = "<div class=\"pop_error_intro\">"+objMsg+"</div>";
    $("body").append(sInnnerMsg);
    */
}

//浏览器版本
function getBrowser(){
    var bName=$.browser;
    var bVersion = "";
    if(bName.msie)   {bVersion="Microsoft Internet Explorer "+bName.version;}
    if(bName.mozilla){bVersion="Mozilla Firefox "+bName.version;}
    if(bName.safari) {bVersion="Apple Safari "+bName.version;}
    if(bName.opera)  {bVersion="Opera "+bName.version;}
    return bVersion;
}

//浏览器版本
function getBS() {
        var OsObject = "";
        if (navigator.userAgent.indexOf("MSIE") > 0) {
            return "MSIE";
        }
        if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
            return "Firefox";
        }
        if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
            return "Safari";
        }
        if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
            return "Camino";
        }
        if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
            return "Gecko";
        }
}

//判断浏览器 
function  isIE(){ 
      if   (window.navigator.userAgent.toString().toLowerCase().indexOf("msie") >=1)
        return true;
      else
        return false;
}

//比较Array
function CompareArray(F,N){
    var arrTemp = new Array();
    for(i in F){
        for(j in N){
            if(F[i]==N[j]){
               arrTemp.push(F[i]) 
            }
        }
    }
    for(i in F){
        for(objtemp in arrTemp){
           if(arrTemp[objtemp]==F[i]){
                F.splice(i,1);
           }
        }
    }
    return F;
}

//查找Array
function ArrayContain(str,arr){
    var flag=false;
    for(i in arr){
        if(arr[i]==str){
            flag=true;
            break;
        }
    }
    return flag;
}
//清除项

function ArrayRemove(str,arr){
    for(var i in arr){
        if(arr[i]==str){
            arr.splice(i,1);
        }
    }
    return arr;
}
//获取url参数
function getQueryStringRegExp(name) 
{ 
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");   
    if (reg.test(location.href)) 
       return unescape(RegExp.$2.replace(/\+/g, " ")); 
        //return RegExp.$2.replace(/\+/g, " "); 
    return ""; 
};

function getQueryStringRegExp1(name) 
{ 
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");   
    if (reg.test(decodeURI(location.href))) 
       return unescape(RegExp.$2.replace(/\+/g, " ")); 
        //return RegExp.$2.replace(/\+/g, " "); 
    return ""; 
};

//参数是否存在
function exitQueryString(name)
{
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");   
    return reg.test(location.href);
} 

//获取地址参数
function GetQueryString(para)
{
	var retval="";
	var s=location.search.replace("?","");
	if(s=="")return "";s = s.split("&");
	for(var i=0;i<s.length;i++)
	if(s[i].toUpperCase().indexOf(para.toUpperCase() + "=")==0)
	retval+=((retval==""?"":", ")+s[i].substr(s[i].indexOf("=")+1,s[i].length));
	return retval;
}


function isIdCard(number)
{
    number = number.toLowerCase();
    var date, Ai;   
    var verify = "10x98765432";   
    var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];   
    var area = ['','','','','','','','','','','','北京','天津','河北','山西','内蒙古','','','','','','辽宁','吉林','黑龙江','','','','','','','','上海','江苏','浙江','安微','福建','江西','山东','','','','河南','湖北','湖南','广东','广西','海南','','','','重庆','四川','贵州','云南','西藏','','','','','','','陕西','甘肃','青海','宁夏','新疆','','','','','','台湾','','','','','','','','','','香港','澳门','','','','','','','','','国外'];   
    var re = number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/i);   
    if(re == null) return false;   
    if(re[1] >= area.length || area[re[1]] == "") return false;   
    if(re[2].length == 12){   
        Ai = number.substr(0, 17);   
        date = [re[9], re[10], re[11]].join("-");   
    }   
    else{   
        Ai = number.substr(0, 6) + "19" + number.substr(6);   
        date = ["19" + re[4], re[5], re[6]].join("-");   
    }   
    if(!this.IsDate(date, "ymd")) return false;   
    var sum = 0;   
    for(var i = 0;i<=16;i++){   
        sum += Ai.charAt(i) * Wi[i];   
    }   
    Ai +=  verify.charAt(sum%11); 
    return (number.length ==15 || number.length == 18 && number == Ai);
}
function IsDate (op, formatString){
  formatString = formatString || "ymd";
  var m, year, month, day;
  switch(formatString){
   case "ymd" :
    m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
    if(m == null ) return false;
    day = m[6];
    month = m[5]*1;
    year =  (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
    break;
   case "dmy" :
    m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
    if(m == null ) return false;
    day = m[1];
    month = m[3]*1;
    year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
    break;
   default :
    break;
  }
  if(!parseInt(month)) return false;
  month = month==0 ?12:month;
  var date =new Date(year, month-1, day);
  return (typeof(date) == "object" && year == date.getFullYear() && month == (date.getMonth()+1) && day == date.getDate());function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
   }
function getLength(strTemp)
{
     var i,sum;
     sum=0;
     for(i=0;i<strTemp.length;i++)
     {
      if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
       sum=sum+1;
      else
       sum=sum+2;
     }
     return sum;
}
function getEvent()
{
    if(document.all)    return window.event;
    func=getEvent.caller;
    while(func!=null)
    {
        var arg0=func.arguments[0];
        if(arg0)
        {
            if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
            {
                return arg0;
            }
        }
        func=func.caller;
    }
return null;
}


/*图片轮转*/
function shadeImg(){
        var shade =document.getElementById("shade");
		if(document.all){
			if(shade.filters.alpha.opacity!=0){        //必须加这个判断，否则频繁点击123按钮时候，淡出淡出会出错
			shade.filters.alpha.opacity-=10;
			setTimeout("shadeImg()",50)
			}
		}
		else{
			if(shade.style.opacity!=0){        //必须加这个判断，否则频繁点击123按钮时候，淡出淡出会出错
			shade.style.opacity-=0.1;
			setTimeout("shadeImg()",50)
			}
		}
}
 
 
function opac(){
        var shade =document.getElementById("shade");
		if(document.all){					//document.all用来判断ie和ff
			shade.filters.alpha.opacity=100;
		}
		else{
			shade.style.opacity=1;
		}
}
 
function display(){
    var Exchange =document.getElementById("img_Exchange");
    var L = Exchange.getElementsByTagName("img").length;
	for(var i=0; i<L; i++){
		Exchange.getElementsByTagName("img")[i].style.display="none";
	}
	for(var j=0; j<L; j++){
		Exchange.getElementsByTagName("a")[j].className="";
	}	
}
 
function switchTag(img,obj){
	display();
	obj.className="this_img";
	document.getElementById(img).style.display="block";
	opac();
	shadeImg();
	clearInterval(t2);
	t2 = window.setInterval("AutoswitchTag()",4000);
}
 
 
function AutoswitchTag(){
	opac();
    var Exchange =document.getElementById("img_Exchange");
    var L = Exchange.getElementsByTagName("img").length;
	var imgs = Exchange.getElementsByTagName("img");
	var links = Exchange.getElementsByTagName("a");
	
	if (imgs.length > 0){
		for(var i=L-1;-1<i&&i<L;i--){
			if(imgs[i].style.display=="block"){
				var n = i - 1;
				if (n < 0) n = L-1;
				display();
				imgs[n].style.display="block";
				links[n].className="this_img";
				shadeImg();
				break;
			}
		}
	}	
}
function checkEnter(e)
{
    var key = window.event ? e.keyCode:e.which;
    var keychar = String.fromCharCode(key);
    reg = /\d/;
    return reg.test(keychar);
}
//取得HTML控件绝对位置
function getAbsPoint(e) {
    var x = e.offsetLeft;
    var y = e.offsetTop;
    while (e = e.offsetParent) {
        x += e.offsetLeft;
        y += e.offsetTop;
    }
    return { "x": x, "y": y };
}
